package pkg.hicph.org;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class StopWorkScreen extends Activity implements OnClickListener  {
    
    public TextView stopWorkInfo, stopWorkTitle;
    public Button actionButton, cancelButton;


	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  
	  requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(
      WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
	  
	  setContentView(R.layout.stopworkscreen);
	  
	  registerViews();
	  setupOnClickListeners();
	  
//	  this.setTitle("You just found this place:");
	  
	  if(Utils.player.money < 30){
		  stopWorkTitle.setText("You have enough money to buy some snacks.");
		  stopWorkInfo.setText("You have more than the 20 dkk you need to eat a snack. You can either go to one of the places that sell it or keep trying to get enough money for a more healthy meal.");
	  }
	  else {
		  stopWorkTitle.setText("You have money to buy a full meal.");
		  stopWorkInfo.setText("You have more than the 30 dkk that you need to have a good full meal. Now nothing stops you to go and eat, and you are already tired.");
		  cancelButton.setVisibility(8);
	  }
	  
	}
	
	
//	private void loadPrefs() {
//		
//		String actionName;
//		
//    	preferences  = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
//    	
//    	actionName = preferences.getString("nextActionName", "");
//    	
//    	Log.d("DIALOG","loaded: " + actionName);
//    	
//    	actionToPerform = Utils.nextAction;
//    	
//    	actionToPerform = Utils.getActionByName(actionName);
//    	Log.d("DIALOG","action: " + actionToPerform.name);
//        
//	}
	
	
	private void registerViews() {
			
		 actionButton = (Button) this.findViewById(R.id.stop_work_action_button);
		 cancelButton = (Button) this.findViewById(R.id.stop_work_cancel_button);
		 stopWorkInfo = (TextView) this.findViewById(R.id.stop_work_dialog_info);
		 stopWorkTitle = (TextView) this.findViewById(R.id.stop_work_dialog_title);
	}

	
	public void setupOnClickListeners() {
        
		actionButton.setOnClickListener(this);
		cancelButton.setOnClickListener(this);

    }
    
	
    public void onClick(View V) {
    	
    	switch(V.getId()) {
    	
    	case R.id.stop_work_action_button:
    		
    		// COMPUTES ACTION
    		
    		if(Utils.visitedBins.length() > 0){
    			Utils.player.dayStory += "You recycled things from " + (int)Utils.visitedBins.length()/3 + " bins.";
    		}
    		else if(Utils.begCount > 0){
    			Utils.player.dayStory += "Some " + Utils.begCount + " people gave you spare change.";			
    		}
    		
    		
    		
    		if(Utils.player.money < 30){
    			Utils.player.dayStory += " Now, you had enough money for some snacks.";
    		}
    		else {
    			Utils.player.dayStory += " It took a bit longer, but you managed to get enough money to eat a full, healthy meal.";
    		}
    		
    		Utils.player.dayStory += " Then, you finally went for your food!\n\n";
    		
    		
    		Utils.gamePhase = Utils.START_EAT_MODE;
    		
    		// CLOSES THE DIALOG
    		this.finish();
    		
    		break;
    		
    	case R.id.stop_work_cancel_button:
    		
    		if(Utils.gamePhase == Utils.PLAY_BEG_MODE){
    			
    		}
    		if(Utils.gamePhase == Utils.PLAY_HF_MODE){
    			
    		}
    		
    		// CLOSES THE DIALOG
    		this.finish();
    		
    		break;
    		
    	}

    }


}



